<template>
	<div></div>
</template>

<script lang="ts">
import { defineComponent, onMounted, getCurrentInstance } from 'vue'

export default defineComponent({
  name: 'compositionApi',
  data(){
	  return {
		  foo:'foo'
	  }
  },
  setup(){
	  // getCurrentInstance() 可以获取组件实例
	  const instance = getCurrentInstance()
	  console.log(instance)
	  
	  onMounted(()=>{
		  console.log(instance.ctx.foo)
		  instance.ctx.bar();
	  })
	  
	  return {
		  
	  }
  },
  methods:{
	  bar(){
		  console.log('我是bar方法')
	  }
  }
})
</script>

<style scoped>

</style>
